<?php

namespace Drupal\shushengyuan\Schemas;

use Drupal\shusy_errand\Entity\ShusyErrand;

/**
 * @OA\Schema(
 *   schema="ErrandItem",
 *   type="object",
 *   description="ErrandItem"
 * )
 */
class ErrandItem extends AbstractBaseModel {

  protected function getEntityType() {
    return 'shusy_errand';
  }

  protected function setValue() {
    if ($this->entity instanceof ShusyErrand) {
      $value = [
        /**
         * @OA\Property(
         *   property="id",
         *   type="integer",
         *   description="ID",
         * ),
         */
        'id' => (int) $this->entity->id,
        /**
         * @OA\Property(
         *   property="city",
         *   type="string",
         *   description="区域",
         * ),
         */
        'city' => (string) $this->entity->city,
        /**
         * @OA\Property(
         *   property="name",
         *   type="string",
         *   description="负责人",
         * ),
         */
        'name' => (string) $this->entity->name,
        /**
         * @OA\Property(
         *   property="phone",
         *   type="string",
         *   description="联系方式",
         * ),
         */
        'phone' => (string) $this->entity->phone,
        'team' => (string) $this->entity->team,
        'isAdmin' => (bool) $this->entity->is_admin,
        'status' => (int) $this->entity->status,
        'statusLabel' => $this->getStatusLabel($this->entity->status),
      ];
      $this->merge($value);
    }
  }

  protected function getStatusLabel(int $status) {
    //状态 0 未提交 1 已通过 2 审核中 3 未通过
    switch ($status) {
      case 0:
        return '未提交';
        break;
      case 1:
        return '已通过';
        break;
      case 2:
        return '审核中';
        break;
      case 3:
        return '未通过';
        break;
    }
    return '';
  }
}
